package com.project.personnel.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.personnel.entity.Department;
import com.project.personnel.entity.Employeeremove;
import com.project.personnel.entity.Position;
import com.project.personnel.service.DepartmentService;
import com.project.personnel.service.EmployeeremoveService;
import com.project.personnel.service.PositionService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;
import com.project.personnel.service.EmployeeremoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author diaominyh
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/employeeremove")
public class EmployeeremoveController {
    @Autowired
    EmployeeremoveService employeeremoveService;
    //查询总调入调出
    @GetMapping("/countremove")
    public List<Integer> countRemove(){
        return employeeremoveService.getremoveinformation();
    }
    @Resource
    private DepartmentService departmentService;
    @Resource
    private PositionService positionService;
    // 查询所有
    @RequestMapping("/employeeremoveList")
    public List<Employeeremove> employeeremoveList(@RequestParam(defaultValue = "1") Integer pageNum, Integer pageSize){
        List<Employeeremove> list = employeeremoveService.selectAll((pageNum-1)*pageSize,pageSize);
        return list;
    }
    // 编辑员工
    @RequestMapping("/update")
    public boolean update(Employeeremove employeeremove){
        boolean b = employeeremoveService.updateById(employeeremove);
        return b;
    }
    // 删除员工
    @RequestMapping("/delete")
    public boolean delete(Employeeremove employeeremove){
        boolean b = employeeremoveService.removeById(employeeremove);
        return b;
    }
    // 添加员工调动
    @RequestMapping("/add")
    public boolean add(@RequestBody Employeeremove employeeremove){
        boolean b = employeeremoveService.save(employeeremove);
        return b;
    }
    // 根据员工姓名或者员工工号模糊查询(包含分页查询)
    @RequestMapping("/Like")
    public List<Employeeremove> getLike(String empName, String workID,@RequestParam(defaultValue = "1") Integer pageNum, Integer pageSize){
        List<Employeeremove> list = employeeremoveService.getLike(empName,workID,(pageNum-1)*pageSize,pageSize);
        return list;
    }
    // 查询编辑所需要的所有部门信息
    @RequestMapping("/departmentgetAll")
    public List<Department> departmentgetAll(){
        List<Department> list = departmentService.list();
        return list;
    }
    // 查询编辑所需要的所有职位信息
    @RequestMapping("/positiongetAll")
    public List<Position> positionsgetAll(){
        List<Position> list = positionService.list();
        return list;
    }
    // 员工调动批量删除
    @DeleteMapping("/del")
    public boolean del(@RequestParam("id") List<Integer> list){
        return employeeremoveService.removeByIds(list);
    }
}

